import pymysql


class DBUtils:
    @classmethod
    def query_db(cls, sql):
        conn = pymysql.connect(host='', port=3306, user='test001', password='123456', database='mianmian', charset='utf8')
        cursor = conn.cursor()
        cursor.execute(sql)
        ret_data = cursor.fetchall()
        cursor.close()
        conn.close()
        return ret_data

    @classmethod
    def uid_db(cls, sql):
        conn = None
        cursor = None
        try:
            conn = pymysql.connect(host='', port=3306, user='test001', password='123456', database='mianmian',
                                   charset='utf8')
            cursor = conn.cursor()
            cursor.execute(sql)
            conn.commit()
        except Exception as e:
            print('数据库操作出错了...')
            if conn is not None:
                conn.rollback()
        finally:
            if cursor is not None:
                cursor.close()
            if conn is not None:
                conn.close()